[Simple] Beginner AJAX script not working, stuck on opening XMLHttpRequest

Posted by Julian H. Lam on Stack Overflow See other posts from Stack Overflow or by Julian H. Lam
Published on 2010-05-08T05:59:26Z Indexed on 2010/05/08 6:08 UTC
Read the original article Hit count: 277

Filed under:

Hopefully, this question isn't too juvenile to ask - but here goes:

I'm trying to learn AJAX, and I'm stuck on a simple content-fetch. Here is my code:

request = getHTTPObject();
function useHttpResponse() {
  if (request.readyState == 4) {
    document.getElementById("p").innerHTML = request.responseText;
  }
}
function update_p() {
  request.open("GET",content.html,true);
  request.onreadystatechange = useHttpResponse;
}

getHTTPObject is correctly defined, and returns a proper XMLHttpObject. As you probably guessed from the excerpt, the element I am trying to update is id'd "p". It calls the script correctly when a button is clicked, no problem there.

The script seems to stop at line 8, at request.open. There's no error, and the script silently ignores anything afterward.

I don't think I've missed anything, but of course, I probably did. Where did I go wrong?

Thanks!

© Stack Overflow or respective owner

Related posts about AJAX